﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.BackgroundJobs;

namespace Xms.Abp.Smsing;

public abstract class SmsSenderBase : ISmsSender
{
    protected IBackgroundJobManager BackgroundJobManager { get; }
    public SmsSenderBase(
        IBackgroundJobManager backgroundJobManager)
    {
        BackgroundJobManager = backgroundJobManager;
    }
    public virtual async Task QueueAsync(SmsMessage smsMessage)
    {
        if (!BackgroundJobManager.IsAvailable())
        {
            await SendAsync(smsMessage);
            return;
        }
        await BackgroundJobManager.EnqueueAsync(smsMessage, smsMessage.Priority);
    }

    public virtual Task SendAsync(SmsMessage smsMessage)
    {
        return SendSmsAsync(smsMessage);
    }

    protected abstract Task SendSmsAsync(SmsMessage smsMessage);

    public virtual void ValidateTemplateParameters(IDictionary<string, string> templateParameters, string[] parameterNames)
    {
    }
}
